//
//  ActionSheetCardAnimationView.swift
//  SwiftUIDemo
//
//  Created by zhouzuosong on 2020/8/23.
//  Copyright © 2020 Kael. All rights reserved.
//

import SwiftUI

struct ActionSheetCardAnimationView: View {
    
    @State var showCard = false
    
    var body: some View {
        VStack(spacing: 40) {
            Text("Hello, World!")
            
            BannerText(text: "测试 BannerText", backgroundColor: .green)
                .frame(maxWidth: .infinity)

            
//            Spacer(minLength: 0)
            
            Button(action: {
                withAnimation {
                    self.showCard.toggle()
                }
            }, label: {
                Text("Show card")
            })
            
            Spacer(minLength: 0)

            Rectangle()
                .fill(Color.orange)
//                .foregroundColor(.blue)
                .frame(width: 320, height: 200)
                .scaleEffect( CGSize(width: 1.0, height: 1.0))
                .opacity(1)
            

            Rectangle()
                .fill(Color.blue)
//                .foregroundColor(.blue)
                .frame(width: 320, height: 200)
                .scaleEffect(self.showCard ? CGSize(width: 1.0, height: 1.0) : CGSize(width: 0, height: 0))
                .opacity(self.showCard ? 1 : 0)
                .cornerRadius(8)
        }
        .animation(.easeIn)
    }
}

struct BannerText : View {
    
    var pageTitle : String = "title"
    var text : String = "text"
    
    var backgroundColor : Color = Color.green
    
    
    var body: some View{
        Text(pageTitle)
            .font(.title)
            .padding()
            
        Text(text)
            .frame(maxWidth: .infinity)
            .font(.headline)
            .padding()
            .foregroundColor(.white)
            .background(backgroundColor)
    }
}

struct ActionSheetCardAnimationView_Previews: PreviewProvider {
    static var previews: some View {
        ActionSheetCardAnimationView()
    }
}
